﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using rock.UI.pictureinfo.xml;

namespace rock.UI.picturexml
{
    public   class HtmlFile
    {
        public String filename;
        public String showname;
        public int orderon; 
    }

    public class XmlUtil
    {
        
        public static List<HtmlFile> getHtmlfiles(String xmlfilename)
        {
            List<HtmlFile> list = new List<HtmlFile>();
            XmlDocument dom = new XmlDocument();
            dom.Load(xmlfilename);//装载XML文档 
             //遍历所有节点 
            foreach (XmlElement rows in dom.DocumentElement.ChildNodes)
            {
                HtmlFile hf = new HtmlFile();
                hf.filename = rows.GetAttribute("filename");
                hf.showname = rows.GetAttribute("showname");
                hf.orderon = int.Parse(rows.GetAttribute("orderon"));
                list.Add(hf);
            }

            return list;
        }

        public static Root parse(String fileName ){
            XmlDocument dom = new XmlDocument();
            dom.Load(fileName);//装载XML文档 


            Root root = new Root();
            String rootName = dom.DocumentElement.GetAttribute("name");
            root.name = rootName;

            //遍历所有节点 
            foreach (XmlElement rows in dom.DocumentElement.ChildNodes)
            {
                Row row = new Row();
                String name = rows.GetAttribute("name");
                int order = int.Parse(rows.GetAttribute("order"));
              //  String dong = rows.GetAttribute("dong");
                String xiaoqu = rows.GetAttribute("xiaoqu");

                row.name = name;
                row.order = order;
               // row.dong = dong;
                row.xiaoqu = xiaoqu;

                //读取数据 
                foreach (XmlElement cols in rows.ChildNodes)
                {
                    //layout="vertical"   order="1"   top="10" left="10"  number="7" style="double" start="1" end="2"
                    String layout = cols.GetAttribute("layout");
                    int order2 = int.Parse(cols.GetAttribute("order"));
                    int top = int.Parse(cols.GetAttribute("top"));
                    int left = int.Parse(cols.GetAttribute("left"));
                    String dong = cols.GetAttribute("dong");
                    String heightmodel = cols.GetAttribute("heightmodel");
                    String widthmodel = cols.GetAttribute("widthmodel");
                    
                    
                    String style = cols.GetAttribute("style");
                    int start = int.Parse(cols.GetAttribute("start"));
                    int end = int.Parse(cols.GetAttribute("end"));

                    Col col = new Col();
                    col.layout = layout;
                    col.order = order2;
                    col.top = top;
                    col.left = left;
                    col.dong = dong;
                    col.style = style;
                    col.start = start;
                    col.end = end;
                    col.heightmodel = heightmodel;
                    col.widthmodel = widthmodel;
                    XmlNode part = cols.SelectSingleNode("part");
                    if (part != null)
                    {
                        String str = part.InnerText;
                        col.parts = str.Split(',');
                    }

                    XmlNode nodouble = cols.SelectSingleNode("nodouble");
                    if (nodouble != null)
                    {
                        String str = nodouble.InnerText;
                        col.ondouble = str.Split(',');
                    }

                    row.cols.Add(col);
                }
                root.rows.Add(row);
            }
            return root;

        }

         
    }
}
